<template>
  <div style="height: 445px; width: 100%; position: relative">
      <div class="pagetop">
          <div style="float: left; width: 100%">
              <div style="float: left; width: 70%; font-size: 18px; padding: 3px; font-weight: 800">{{ inn_remindtxt }}</div>
              <div style="float: left; width: 30%; margin-top: 3px">
                  <table style="float: right">
                      <tr>
                          <td>
                              <div>
                                  <!--v-if="barcodearrivemode!='0'"--->
                                  <!--=0单条不显示-->
                                  <el-button @click="singleRcv" icon="el-icon-document-copy">{{ FunInfos.btntxt1 }}</el-button>
                              </div>
                          </td>
                          <td>
                              <div v-show="packagemustscan1by1 != '1'">
                                  <!--=1必须单条，全部不显示--->
                                  <el-button @click="confirmRcv" icon="el-icon-document-checked">{{ FunInfos.btntxt2 }}</el-button>
                              </div>
                          </td>
                          <td>
                              <el-button @click="cancelRcv" icon="el-icon-close">关 闭</el-button>
                          </td>
                      </tr>
                  </table>
              </div>
          </div>
      </div>
      <div class="pagecenter">
          <div class="middle-center">
              <vxe-table show-overflow ref="xTablePop" height="auto" :select-config="{ reserve: true }" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :data.sync="list" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @current-change="detailretrieve" :loading="loading" :key="xTablePopKey">
                  <vxe-table-column field="req_groupna" title="分单类别 " width="106" header-align="center">
                      <template v-slot="{ row }">{{ !row.req_groupna ? "未分类" : row.req_groupna }}</template>
                  </vxe-table-column>
                  <vxe-table-column field="specimen_name" title="标本类型 " width="84" header-align="center"></vxe-table-column>
                  <vxe-table-column field="samplecnt" title="标本数 " width="65" header-align="center"> </vxe-table-column>
                  <template v-slot:fix>
                      <div style="font-size: 12px; padding-top: 3px; background-color: #fff; text-align: center; cursor: pointer" @click="ShowAllData">
                          <span style="color: red; color: blue">共: {{ samplesum }}</span>
                      </div>
                  </template>
              </vxe-table>
          </div>
          <div class="middle-right">
              <vxe-table show-overflow ref="xTablePop" height="auto" :select-config="{ reserve: true }" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :data="rowclick ? tableData2 : tableData1" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe :row-class-name="rowClassName" class="mytable-style">
                  <vxe-table-column field="barcode" title="条码号 " width="110" header-align="center"></vxe-table-column>
                  <vxe-table-column field="req_groupna" title="分单类别 " width="86" header-align="center">
                      <template v-slot="{ row }">
                          <div v-bind:style="{ background: $pub.ColorChange(row.tube_color), color: $pub.colorConvert(row.tube_color) }" style="height: 20px; width: 120px">{{ !!row.req_groupna ? row.req_groupna : "" }}</div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="pat_no" title="病人号" width="105" header-align="center"></vxe-table-column>
                  <vxe-table-column field="pat_name" title="姓名" width="60" header-align="center"></vxe-table-column>
                  <vxe-table-column field="pat_sexname" title="性别 " width="50" header-align="center" align="center"></vxe-table-column>
                  <vxe-table-column field="req_bedno" title="床号 " width="80" header-align="center"></vxe-table-column>
                  <vxe-table-column field="emer_flag" title="加急 " width="50" header-align="center" align="center">
                      <template v-slot="{ row }">
                          <div style="color: red">{{ row.emer_flag == "1" ? "急" : "" }}</div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="req_statname" title="申请状态 " width="82" header-align="center"></vxe-table-column>
                  <vxe-table-column field="req_deptname" title="申请科室 " width="124" header-align="center"></vxe-table-column>
                  <vxe-table-column field="req_wardname" title="病人病区 " width="125" header-align="center"></vxe-table-column>
                  <vxe-table-column field="sample_items" title="项目描述 " width="203" header-align="center"></vxe-table-column>
                  <vxe-table-column field="amount" title="金额 " width="75" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="req_docname" title="申请医生 " width="75" header-align="center"></vxe-table-column>
                  <vxe-table-column field="pat_typename" title="病人类型 " width="70" header-align="center"></vxe-table-column>
                  <vxe-table-column field="create_dt" title="条码生成时间 " width="130" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                  <!-- <vxe-table-column field="rcvmsg" title="消息 " width="105" header-align="center"></vxe-table-column> -->
                  <vxe-table-column field="retrcvmsg" title="签收消息 " width="205" header-align="center"></vxe-table-column>
                  <template v-slot:fix>
                      <div style="font-size: 12px; padding-top: 3px; background-color: #fff; text-align: center">
                          <span style="color: red; color: blue">共: {{ sumcnt }}</span
                          ><span style="color: red; margin-left: 35px; color: blue">已收: {{ rcvcnt }}</span
                          ><span style="color: red; margin-left: 35px">未收: {{ unrcvcnt }}</span
                          ><span style="color: transparent">{{ rcvkey }}</span>
                      </div>
                  </template>
              </vxe-table>
          </div>
      </div>
      <el-dialog ref="edialog01" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="签收提示" :visible.sync="diagPromiseVisible1">
          <div v-for="msg in msglist" :key="msg.title" style="over-flow: auto">
              <h3 style="color: red">{{ msg.Item1 }}</h3>
              <h5 v-html="msg.Item2"></h5>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="diagPromise_click(-1)">确 定</el-button>
          </span>
      </el-dialog>

      <el-dialog ref="edialog02" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="签收提示" :visible.sync="diagPromiseVisible2">
          <div v-for="msg in msglist" :key="msg.title" style="over-flow: auto">
              <h3 style="color: red">{{ msg.Item1 }}</h3>
              <h5 v-html="msg.Item2"></h5>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="diagPromise_click(1)">是</el-button>
              <el-button @click="diagPromise_click(0)">否</el-button>
          </span>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  props: { tableData1: { type: Array }, appendtobody: { type: Boolean, default: true }, remindtxt: { type: String }, userinfoval: { type: String }, name: { type: String }, trans: { type: String }, packbarcode: { type: String } },
  data() {
      return {
          inn_remindtxt: this.remindtxt,
          tableData2: [],
          tableData4: [],
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          keyLocalConfig: {
              isArrow: true,
          },
          // rcvcnt: 0,
          //unrcvcnt: 0,
          hasRcvcnt: 0,
          rcvkey: 0,
          rowclick: false,
          loading: false,
          rcv_invalidmsgbox: "",
          rcv_dupnomsgbox: "",
          rcv_showinvalid: "",
          diagPromiseVisible1: false,
          diagPromiseVisible2: false,
          msglist: [],
          translist: {},
          packagebarcode: "",
          transtype: "",
          RcvFunInfo: {
              LIS211: {
                  URL: "LIS/LIS2/LIS211",
                  btntxt1: "单条确认",
                  btntxt2: "全部确认",
                  action: "scanbarcode",
              },
              LIS212: {
                  URL: "LIS/LIS2/LIS212",
                  btntxt1: "单条签收",
                  btntxt2: "全部签收",
                  action: "packageall",
              },
              LIS221: {
                  URL: "LIS/LIS2/LIS221",
                  btntxt1: "单条签收",
                  btntxt2: "全部签收",
                  action: "packageall",
              },
              LIS222: {
                  URL: "LIS/LIS2/LIS222",
                  btntxt1: "单条确认",
                  btntxt2: "全部确认",
                  action: "packagescan1by1",
              },
              NBS311: {
                  URL: "NBS/NBS3/NBS311",
                  btntxt1: "单条签收",
                  btntxt2: "全部签收",
                  action: "packageall",
              },
          },
          barcodearrivemode: "", //0=仅更新包条码交接时间，只能扫描包条码，扫描后弹窗有确认和取消按钮，确认的时候再更新状态
          packagemustscan1by1: "", //打包条码必须解包逐个扫描
          ConfirmArriveFlag: "0",
          xTablePopKey: 0,
          transobj: "",
          allowergrouprcvduplicate: "",
          isclickconfirmbtn: "", //是否点击送达确认按钮进行送达
      };
  },
  created() {
      this.InitPage(); //初始化主列表
  },
  mounted() {
      //that
      //alert("11," + this.trans);
      this.transobj = this.trans;
  },
  updated() {
      //this
      //alert("22," + this.trans);
      this.transobj = this.trans;
  },
  watch: {
      remindtxt(value) {
          this.inn_remindtxt = value;
      },
      // remindtxt(value) {
      //     if (this.remindtxt.indexOf("所有") < 0) {
      //         this.loading = true;
      //     } else {
      //         this.loading = false;
      //     }
      // },
      transobj(value, oldvalue) {
          //LIS211,LIS212,LIS222监听,获取包条码信息
          if (!!value) {
              let arr = value.split("|");
              this.packagebarcode = arr[0].trim(); //this.translist.packagebarcode;
              this.transtype = arr[1].trim(); //this.translist.transtype;
              this.$pub.Log("获取包条码 packagebarcode= " + this.packagebarcode);
          } else {
              this.transtype = "";
              this.packagebarcode = "";
          }
      },
      deep: true,
  },
  computed: {
      sumcnt() {
          if(this.tableData1){
              return this.tableData1.length;
          }
          else{
              return 0;
          }
      },
      rcvcnt() {
          if(this.tableData1){
              //检测状态是否>=4来判断条码是否签收成功
              let data = this.tableData1.filter((item) => item !=null&&  Number(item.req_stat) >= 4);
              return data.length;
          }
      },
      unrcvcnt() {
          return this.tableData1.length - this.rcvcnt;
      },
      list() {
          try {
              if (this.tableData1.length > 0) {
                  let data = this.group(this.tableData1, function (item) {
                      //   console.log(item);
                      return item.req_groupna + "," + item.specimen_name;
                  });
                  return data;
              }
          } catch (e) {
              this.$alert("出错：" + e);
          }
      },
      samplesum() {
          return XEUtils.sum(this.list, "samplecnt");
      },
      FunInfos() {
          // console.log("sa", this.name);
          return this.RcvFunInfo[this.name];
      },
  },
  methods: {
      InitPage() {
          this.$tool
              .request({
                  url: this.FunInfos.URL,
                  method: "post",
                  data: {
                      action: "getoptions",
                  },
              })
              .then((res) => {
                  //console.log("res", res);
                  if (this.name == "LIS211" || this.name == "LIS222") {
                      //   0=仅更新包条码交接时间，只能扫描包条码，扫描后弹窗有确认和取消按钮，确认的时候再更新状态
                      //   1=仅记录申请单送达日志
                      //   2=更新申请单送达时间和送达人
                      // alert(res.barcodearrivemode);
                      this.barcodearrivemode = res.barcodearrivemode; //== "" ? "0" : "1";
                      this.packagemustscan1by1 = res.packagemustscan1by1; // == "" ? "0" : "1"; //打包条码必须解包逐个扫描
                  }
                  if (this.name == "LIS212" || this.name == "NBS311") {
                      this.rcv_invalidmsgbox = res.rcv_invalidmsgbox; //签收异常总是弹出提示框
                      this.rcv_dupnomsgbox = res.rcv_dupnomsgbox; //重复签收不弹窗
                      this.rcv_showinvalid = res.rcv_showinvalid; //列表中显示无效签收的数据
                  }
                  if (this.name == "LIS221") {
                      this.rcv_invalidmsgbox = res.rcv_invalidmsgbox; //签收异常总是弹出提示框
                      this.rcv_dupnomsgbox = res.rcv_dupnomsgbox; //重复签收不弹窗
                      this.rcv_showinvalid = res.rcv_showinvalid; //列表中显示无效签收的数据
                      this.allowergrouprcvduplicate = res.allowergrouprcvduplicate; //工作组重复签收时操作方式  0 不提醒|1 提醒|2 拒绝
                  }
                  if(this.name == "LIS211"){
                      this.isclickconfirmbtn = res.isclickconfirmbtn; //是否点击送达确认按钮进行送达
                  }
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      group(list, f) {
          //分组函数
          const groups = {};
          list.forEach(function (re) {
              if(re){
                  const group = f(re);
                  groups[group] = groups[group] || [];
                  groups[group].push(re);
              }
          });
          return Object.keys(groups).map(function (group) {
              let groupLabel = group.split(","); //根据“，”切割成数组（可自定义）
              return {
                  req_groupna: groupLabel[0], //分单类别
                  specimen_name: groupLabel[1], //标本类型
                  samplecnt: groups[group].length, //
              };
          });
      },
      async singleRcv() {
          switch (this.name) {
              case "LIS211":
                  this.$emit("appendDialog", this.tableData1, this.packagebarcode);
                  break;
              case "LIS212":
              case "NBS311":
                  //单条确认,先调用后台的PackageArrive方法更改包的状态,然后在每扫描一个条码调用后台的scanbarcode方法，调用时要传入包条码号packagebarcode，要更新包明细的扫描时间
                  const result212 = await this.packageArrive("");
                  console.log(result212);
                  if (result212.Item1 == "1") {
                      this.$emit("appendDialog", this.tableData1, this.packagebarcode);
                  } else {
                      this.$alert("签收失败！" + result212.msg, "提示");
                  }
                  break;
              case "LIS221":
                  //单条确认,先调用后台的PackageArrive方法更改包的状态,然后在每扫描一个条码调用后台的scanbarcode方法，调用时要传入包条码号packagebarcode，要更新包明细的扫描时间
                  const result221 = await this.packageArrive("");
                  console.log(result221);
                  if (result221.Item1 == "1") {
                      this.$emit("appendDialog", this.tableData1, this.packagebarcode);
                  } else {
                      this.$alert("签收失败！" + result212.msg, "提示");
                  }
                  break;
              case "LIS222":
                  //如果点击了单条确认，那么要先调用后台的PackageArrive方法，packageconfirm=2。
                  const result222 = await this.packageArrive("2");
                  if (result222.Item1 == "1") {
                      this.$emit("appendDialog", this.tableData1, this.packagebarcode);
                  } else {
                      this.$alert("签收失败！" + result222.msg, "提示");
                  }
                  break;
              default:
                  this.$emit("appendDialog", this.tableData1, this.packagebarcode);
                  break;
          }
      },
      async confirmRcv() {
          switch (this.name) {
              case "LIS211":
                  await this.RcvLis211();
                  break;
              case "LIS212":
              case "NBS311":
                  await this.RcvLis212();
                  break;
              case "LIS221":
                  await this.RcvLis221();
                  break;
              case "LIS222":
                  await this.RcvLis222();
              default:
                  break;
          }
      }, //标本送达全部确认
      async RcvLis211() {
          if(this.isclickconfirmbtn == "1"){
              //点击送达按钮进行送达，直接返回确认信息
              this.ConfirmArriveFlag = "1";
              this.$alert("已全部确认，共" + this.tableData1.length + "笔,成功" + this.tableData1.length + "笔，失败0笔！");
          } else {
              try {
                  const res = await this.$tool.request({
                      url: this.FunInfos.URL,
                      method: "post",
                      data: {
                          action: "packageall",
                          senduser: this.userinfoval,
                          packageBarcode: this.packagebarcode,
                          transtype: this.transtype,
                      },
                  });
                  //     console.log("LIS211", res);
                  switch (res.flag) {
                      case 1:
                          this.ConfirmArriveFlag = "1";
                          this.$alert("已全部确认，共" + this.tableData1.length + "笔,成功" + this.tableData1.length + "笔，失败0笔！");
                          break;
                      default:
                          this.$alert("确认失败：" + res.msg);
                          break;
                  }
              } catch (e) {
                  this.$alert(e);
              }
          }
      }, //标本签收全部签收
      async RcvLis212() {
          try {
              //全部确认，要先调用后台的PackageArrive方法更改包的状态,然后再逐个条码调用签收的方法
              const result = await this.packageArrive("");
              if (result.Item1 == "1") {
                  let object = this.tableData1;
                  let barnum = 0;
                  let alen = object.length;
                  for (const row of object) {
                      barnum++;
                      console.log("barnum",barnum);
                      this.inn_remindtxt = "正在签收第" + barnum + "个条码，条码号" + row.barcode + " (" + barnum + "/" + alen + ")";
                      const res = await this.$tool.request({
                          url: this.FunInfos.URL,
                          method: "post",
                          data: {
                              action: this.name == "NBS311" ? "ScanBarcode": "scanbarcode",
                              barcode: row.barcode,
                              isPackRcv: "0", //0标识不是包条码
                              senduser: this.userinfoval,
                              packageBarcode: this.packagebarcode,
                              transtype: this.transtype,
                          },
                      });
                      // console.log("dddd", res);
                      switch (res.flag) {
                          case 1:
                              row.rcvflag = "1"; //rcvflag标识是否有效签收(1)，进而主列表中判断是否显示无效签收的数据
                              row.retrcvmsg = await res.rcvmsg; //表格显示签收消息
                              row.receive_dt = await res.master.receive_dt;
                              row.receive_user = await res.master.receive_user;
                              row.recieve_username = await res.master.recieve_username;
                              row.receive_host = await res.master.receive_host;
                              row.receiveaddr = await res.master.receiveaddr;
                              row.receive1_dt = await res.master.receive1_dt;
                              row.receive1_user = await res.master.receive1_user;
                              row.recieve1_username = await res.master.recieve1_username;
                              row.prereport_dt = await res.master.prereport_dt;
                              row.req_stat = await res.master.req_stat;
                              row.req_statname = await res.master.req_statname;
                              this.hasRcvcnt++;
                              this.rcvkey++;
                              break;
                          case -1:
                              //失败(有弹窗)->点确定->关闭dialog
                              let msg1 = row.barcode + "(" + row.pat_name + ")签收失败,";
                              row.rcvflag = "-1";
                              row.retrcvmsg = await this.msginfo(res.msgList, msg1); //表格显示签收消息
                              // let str = row.barcode + "<strong>签收失败</strong>" + row.retrcvmsg;
                              this.msglist = await this.msginfoList(res.msgList, msg1); //弹窗显示签收消息
                              console.log("row.retrcvmsg",row.retrcvmsg);
                              await this.rcvmsgfault(-1, row.barcode, row.retrcvmsg);
                              this.rcvkey++;
                              break;
                          case 0:
                              //提示(有弹窗)->是与否->走入dialogok
                              let msg2 = row.barcode + "(" + row.pat_name + ")是否签收？此为";
                              row.rcvflag = "0"; //初始值设为无效签收
                              row.retrcvmsg = await this.msginfo(res.msgList, msg2); //表格显示签收消息
                              this.msglist = await this.msginfoList(res.msgList, msg2); //弹窗显示消息
                              let retdata = await this.rcvmsgfault(0, row.barcode, res.rcvmsg);
                              if (!retdata) break;
                              switch (retdata.flag) {
                                  case 1:
                                      //条码签收成功
                                      row.rcvflag = "1"; //改无效签收为有效签收
                                      row.retrcvmsg = await retdata.msg; //表格显示签收消息
                                      if (retdata.master) {
                                          row.receive_dt = await retdata.master.receive_dt;
                                          row.receive_user = await retdata.master.receive_user;
                                          row.recieve_username = await retdata.master.recieve_username;
                                          row.receive_host = await retdata.master.receive_host;
                                          row.receiveaddr = await retdata.master.receiveaddr;
                                          row.receive1_dt = await retdata.master.receive1_dt;
                                          row.receive1_user = await retdata.master.receive1_user;
                                          row.recieve1_username = await retdata.master.recieve1_username;
                                          row.prereport_dt = await retdata.master.prereport_dt;
                                          row.req_stat = await retdata.master.req_stat;
                                          row.req_statname = await retdata.master.req_statname;
                                      }
                                      this.hasRcvcnt++;
                                      break;
                                  case -1:
                                      //条码签收失败
                                      let msg3 = row.barcode + "(" + row.pat_name + ")签收失败,";
                                      row.rcvflag = "-1";
                                      row.retrcvmsg = await this.msginfo(retdata.msgList, msg3); //表格显示签收消息
                                      this.msglist = await this.msginfoList(retdata.msgList, msg3); //弹窗显示签收消息
                                      await this.rcvmsgfault(-1, "", "");
                                      break;
                              }
                              this.rcvkey++;
                              break;
                          case -99:
                              //出错->直接显示信息
                              row.rcvflag = "-99";
                              row.retrcvmsg = res.errmsg; //表格显示签收消息
                              this.$alert(res.errmsg, "提示");
                              this.rcvkey++;
                              break;
                      }
                  }
                  this.inn_remindtxt = await ("所有条码扫描完成，本次成功签收" + this.hasRcvcnt + "条");
              } else {
                  this.$alert("签收失败！" + result.Item2, "提示");
              }
          } catch (e) {}
      }, //LIS212,LIS222全部签收与单条签收调用这个方法
      packageArrive(packageconfirm) {
          return this.$tool.request({
              url: this.name == "NBS311"? "LIS/LIS2/LIS212" : this.FunInfos.URL,
              method: "post",
              data: {
                  action: "packagearrive",
                  packagebarcode: this.packagebarcode,
                  packageconfirm: packageconfirm,
              },
          });
      },
      // 工作组签收
      async RcvLis221() {
          try {
              //全部确认，要先调用后台的PackageArrive方法更改包的状态,然后再逐个条码调用签收的方法
              let senduser = this.userinfoval.split(":")[0];
              let userno = this.userinfoval.split(":")[1];
              const result = await this.packageArrive("");
              if (result.Item1 == "1") {
                  let object = this.tableData1;
                  let barnum = 0;
                  let alen = object.length;
                  for (const row of object) {
                      barnum++;
                      this.inn_remindtxt = "正在签收第" + barnum + "个条码，条码号" + row.barcode + " (" + barnum + "/" + alen + ")";
                      const res = await this.$tool.request({
                          url: this.FunInfos.URL,
                          method: "post",
                          data: {
                              action: "scanbarcode",
                              barcode: row.barcode,
                              isPackRcv: "0", //0标识不是包条码
                              senduser: senduser,
                              userno: userno,
                              packageBarcode: this.packagebarcode,
                              transtype: this.transtype,
                          },
                      });
                      // console.log("dddd", res);
                      switch (res.flag) {
                          case 1:
                              row.rcvflag = "1"; //rcvflag标识是否有效签收(1)，进而主列表中判断是否显示无效签收的数据
                              row.retrcvmsg = await res.rcvmsg; //表格显示签收消息
                              row.receive_dt = await res.master.receive_dt;
                              row.receive_user = await res.master.receive_user;
                              row.recieve_username = await res.master.recieve_username;
                              row.receive_host = await res.master.receive_host;
                              row.receiveaddr = await res.master.receiveaddr;
                              row.receive1_dt = await res.master.receive1_dt;
                              row.receive1_user = await res.master.receive1_user;
                              row.recieve1_username = await res.master.recieve1_username;
                              row.prereport_dt = await res.master.prereport_dt;
                              row.req_stat = await res.master.req_stat;
                              row.req_statname = await res.master.req_statname;
                              this.hasRcvcnt++;
                              this.rcvkey++;
                              break;
                          case -1:
                              //失败(有弹窗)->点确定->关闭dialog
                              let msg1 = row.barcode + "(" + row.pat_name + ")签收失败,";
                              row.rcvflag = "-1";
                              row.retrcvmsg = await this.msginfo(res.msgList, msg1); //表格显示签收消息
                              // let str = row.barcode + "<strong>签收失败</strong>" + row.retrcvmsg;
                              this.msglist = await this.msginfoList(res.msgList, msg1); //弹窗显示签收消息
                              await this.rcvmsgfault(-1, row.barcode, row.retrcvmsg);
                              this.rcvkey++;
                              break;
                          case 0:
                              //提示(有弹窗)->是与否->走入dialogok
                              let msg2 = row.barcode + "(" + row.pat_name + ")是否签收？此为";
                              row.rcvflag = "0"; //初始值设为无效签收
                              row.retrcvmsg = await this.msginfo(res.msgList, msg2); //表格显示签收消息
                              this.msglist = await this.msginfoList(res.msgList, msg2); //弹窗显示消息
                              let retdata = await this.rcvmsgfault(0, row.barcode, res.rcvmsg);
                              if (!retdata) break;
                              switch (retdata.flag) {
                                  case 1:
                                      //条码签收成功
                                      row.rcvflag = "1"; //改无效签收为有效签收
                                      row.retrcvmsg = await retdata.msg; //表格显示签收消息
                                      if (retdata.master) {
                                          row.receive_dt = await retdata.master.receive_dt;
                                          row.receive_user = await retdata.master.receive_user;
                                          row.recieve_username = await retdata.master.recieve_username;
                                          row.receive_host = await retdata.master.receive_host;
                                          row.receiveaddr = await retdata.master.receiveaddr;
                                          row.receive1_dt = await retdata.master.receive1_dt;
                                          row.receive1_user = await retdata.master.receive1_user;
                                          row.recieve1_username = await retdata.master.recieve1_username;
                                          row.prereport_dt = await retdata.master.prereport_dt;
                                          row.req_stat = await retdata.master.req_stat;
                                          row.req_statname = await retdata.master.req_statname;
                                      }
                                      this.hasRcvcnt++;
                                      break;
                                  case -1:
                                      //条码签收失败
                                      let msg3 = row.barcode + "(" + row.pat_name + ")签收失败,";
                                      row.rcvflag = "-1";
                                      row.retrcvmsg = await this.msginfo(retdata.msgList, msg3); //表格显示签收消息
                                      this.msglist = await this.msginfoList(retdata.msgList, msg3); //弹窗显示签收消息
                                      await this.rcvmsgfault(-1, "", "");
                                      break;
                              }
                              this.rcvkey++;
                              break;
                          case -99:
                              //出错->直接显示信息
                              row.rcvflag = "-99";
                              row.retrcvmsg = res.errmsg; //表格显示签收消息
                              this.$alert(res.errmsg, "提示");
                              this.rcvkey++;
                              break;
                          case 66:
                              if (this.allowergrouprcvduplicate == "2") {
                                  that.barcodetxt = barcode + "  已签收，不能重复签收";
                              } else if (this.allowergrouprcvduplicate == "1") {
                                  let msg2 = "【" + row.barcode + "】该条码已被签收，是否重复签收?";
                                  row.rcvflag = "0"; //初始值设为无效签收
                                  row.retrcvmsg = await this.msginfo(res.msgList, msg2); //表格显示签收消息
                                  this.msglist = await this.msginfoList(res.msgList, msg2); //弹窗显示消息
                                  let retdata = await this.grouprcvmsgfault(row.barcode, senduser, userno);
                                  if (!retdata) break;
                                  switch (retdata.flag) {
                                      case 1:
                                          //条码签收成功
                                          row.rcvflag = "1"; //改无效签收为有效签收
                                          row.retrcvmsg = await retdata.msg; //表格显示签收消息
                                          if (retdata.master) {
                                              row.receive_dt = await retdata.master.receive_dt;
                                              row.receive_user = await retdata.master.receive_user;
                                              row.recieve_username = await retdata.master.recieve_username;
                                              row.receive_host = await retdata.master.receive_host;
                                              row.receiveaddr = await retdata.master.receiveaddr;
                                              row.receive1_dt = await retdata.master.receive1_dt;
                                              row.receive1_user = await retdata.master.receive1_user;
                                              row.recieve1_username = await retdata.master.recieve1_username;
                                              row.prereport_dt = await retdata.master.prereport_dt;
                                              row.req_stat = await retdata.master.req_stat;
                                              row.req_statname = await retdata.master.req_statname;
                                          }
                                          this.hasRcvcnt++;
                                          break;
                                      case -1:
                                          //条码签收失败
                                          let msg3 = row.barcode + "(" + row.pat_name + ")签收失败,";
                                          row.rcvflag = "-1";
                                          row.retrcvmsg = await this.msginfo(retdata.msgList, msg3); //表格显示签收消息
                                          this.msglist = await this.msginfoList(retdata.msgList, msg3); //弹窗显示签收消息
                                          await this.rcvmsgfault(-1, "", "");
                                          break;
                                  }
                                  this.rcvkey++;
                              }
                              break;
                      }
                  }
                  this.inn_remindtxt = await ("所有条码扫描完成，本次成功签收" + this.hasRcvcnt + "条");
              } else {
                  this.$alert("签收失败！" + result.Item2, "提示");
              }
          } catch (e) {}
      },

      grouprcvmsgfault(barcode, senduser, userno) {
          return new Promise((s, f) => {
              this.$refs.edialog02
                  .ShowDialog()
                  .then(() => {
                      let data = this.gruopdialogok(barcode, senduser, userno);
                      s(data);
                      return;
                  })
                  .catch(() => {
                      s();
                      return;
                  });
          });
      },
      async gruopdialogok(barcode, senduser, userno) {
          try {
              const res = await this.$tool.request({
                  url: "LIS/LIS2/LIS221",
                  method: "post",
                  data: {
                      action: "grouprcvbarcode",
                      barcode: barcode,
                      senduser: senduser,
                      userno: userno,
                      labgroupid: "",
                  },
              });
              return res;
          } catch (e) {
              this.$message.warning(e);
          }
      },

      //标本流转全部确认
      async RcvLis222() {
          try {
              const result = await this.packageArrive("1");
              if (result.Item1 == "1") {
                  if (this.barcodearrivemode == "0" || this.barcodearrivemode == "1") {
                      //  如果选项“标本扫描操作”LIS222_BARCODEARRIVEMODE是0或1，就不需要再对单个条码逐个调用了
                  } else {
                      //如果为2要签收标本，那还是要逐个调用的,逐个调用packagescan1by1时不需要传入packagebarcode
                      let index = -1;
                      for (const item of this.tableData1) {
                          index++;
                          const res = await this.$tool.request({
                              url: this.FunInfos.URL,
                              method: "post",
                              data: {
                                  action: "packagescan1by1",
                                  senduser: this.userinfoval,
                                  barcode: item.barcode,
                              },
                          });
                          //console.log("LIS222", res);
                          switch (res.flag) {
                              case 1:
                                  if (!!item.req_stat) {
                                      //过滤掉没出错但没有获取到申请单的数据
                                      item.packagebarcode = res.packagebarcode;
                                      item.cpperformlabgroup = res.reclabgroupid == null ? "null" : res.reclabgroupid;
                                      item.cpperformdept = res.recdept == null ? "null" : res.recdept;
                                      //   console.log("2121", res.recdept);
                                      if (index === this.tableData1.length - 1) {
                                          item.lastbarcode = item.barcode;
                                          item.lastpatname = item.pat_name;
                                          this.$emit("change", item, true);
                                      } else {
                                          item.lastbarcode = "";
                                          item.lastpatname = "";
                                          this.$emit("change", item, false);
                                      }
                                  }
                                  break;
                              default:
                                  let msg3 = item.barcode + "确认失败！";
                                  this.msglist = await this.msginfoList(res.msgList, msg3); //弹窗显示签收消息
                                  await this.rcvmsgfault(1, "", "");
                                  if (index === this.tableData1.length - 1) {
                                      this.$emit("change", null, true);
                                  } else {
                                      this.$emit("change", null, false);
                                  }
                                  break;
                          }
                      }
                  }
              } else {
                  this.$alert("签收失败！" + result.Item2, "提示");
              }
          } catch (e) {
              this.$alert("出错" + e);
          }
      }, //LIS212通用弹窗
      rcvmsgfault(index, barcode, rcvmsg) {
          switch (index) {
              case -1: //失败(有弹窗)->点确定->关闭dialog
                  return new Promise((s, f) => {
                      let flag = true; //判断是不是重复签收的条码
                      if (this.rcv_dupnomsgbox == "1") {
                          //判断是否是重复签收的
                          if (rcvmsg.indexOf("重复签收的条码") > -1) {
                              flag = false;
                          }
                      }

                      if (flag) {
                          //1.重复签收不弹窗
                          //2.签收异常总是弹出提示框
                          if (this.rcv_invalidmsgbox == "1") {
                              this.$refs.edialog01.ShowDialog().then(() => {
                                  s();
                                  return;
                              });
                          }
                      }
                      else
                      {
                          s();
                          return;
                      }
                  });
              case 0: //提示(有弹窗)->是与否->走入dialogok
                  return new Promise((s, f) => {
                      this.$refs.edialog02
                          .ShowDialog()
                          .then(() => {
                              let data = this.dialogok(barcode, rcvmsg);
                              s(data);
                              return;
                          })
                          .catch(() => {
                              s();
                              return;
                          });
                  });
              case 1: //正常的弹出确认窗
                  return new Promise((s, f) => {
                      this.$refs.edialog01.ShowDialog().then(() => {
                          s();
                          return;
                      });
                  });
          }
      },

      diagPromise_click(t) {
          if (t == 0) {
              //点了取消按钮
              this.$refs.edialog02.Cancel();
          } else if (t == 1) {
              //点了确定按钮
              this.$refs.edialog02.Confirm();
          } else {
              this.$refs.edialog01.Confirm();
          }
      },
      async dialogok(barcode, rcvmsg) {
          try {
              const res = await this.$tool.request({
                  url: this.FunInfos.URL,
                  method: "post",
                  data: {
                      action: "rcvbarcode",
                      barcode: barcode,
                      rcvmsg: rcvmsg,
                      //   senduser: this.userinfoval
                  },
              });
              return res;
          } catch (e) {
              this.$message.warning(e);
          }
      }, //通用消息处理
      async msginfo(msg, name) {
          let gmsg = "";
          msg.forEach((item) => {
              if (gmsg == "") {
                  gmsg = name + "," + item.Item1;
              } else {
                  gmsg = gmsg + "," + item.Item1;
              }
          });
          return gmsg;
      }, //通用消息列表处理
      async msginfoList(msglist, name) {
          if (msglist.length > 0) {
              msglist.forEach((item) => {
                  item.Item1 = name + item.Item1;
              });
          }
          return msglist;
      }, //关闭
      async cancelRcv() {
          this.tableData2 = [];
          switch (this.name) {
              case "LIS211": //标本送达
                  if (this.ConfirmArriveFlag == "1") {
                      this.$emit("cancel", this.tableData1, "suc"); //全部签收后关闭弹窗
                      this.ConfirmArriveFlag = "0";
                  } else {
                      this.$emit("cancel", [], "suc"); //全部签收后关闭弹窗,暂时注释
                  }
                  break;
              case "NBS311":
              case "LIS212": //标本签收
                  let retdata = this.tableData1.filter((item) =>item !=null && Number(item.req_stat) >= 4);
                  this.$emit("cancel", retdata, "suc"); //全部签收后关闭弹窗
                  break;
              case "LIS221": //工作组标本签收
                  let retdata1 = this.tableData1.filter((item) => item !=null && Number(item.req_stat) >= 41);
                  this.$emit("cancel", retdata1, "suc"); //全部签收后关闭弹窗
                  break;
              case "LIS222": //标本流转打包
                  let retdata2 = this.tableData1.filter((item) => item !=null && Number(item.req_stat) >= 4);
                  this.$emit("cancel", retdata2, "suc"); //全部确定后关闭弹窗
                  break;
          }
          // this.$emit("cancel", [], "cls");
      }, //行选中
      detailretrieve({ row }) {
          this.rowclick = true;
          if (this.tableData1.length > 0) {
              let data = this.tableData1.filter((item) => {
                  return item.specimen_name == row.specimen_name && item.req_groupna == row.req_groupna;
              });
              this.tableData2 = data;
          } else {
              this.tableData2 = XEUtils.clone(this.tableData1, true);
          }
      },
      ShowAllData() {
          this.rowclick = false;
          this.$refs.xTablePop.clearCurrentRow();
          this.xTablePopKey++;
      },
      rowClassName({ row, rowIndex }) {
          if ( row !=null && row.req_stat == null) {
              //此时包条码中的数据req_stat不可能为null
              return "row-red";
          }
      },
  },
};
</Script>

<style scoped>
.pagetop {
  width: 100%;
  height: 35px;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  height: 400px;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 690px;
  overflow: auto;
}

.middle-right {
  position: absolute;
  height: 100%;
  width: 685px;
  right: 0px;
}

.table1style tr td {
  padding: 0px 2px 0px 2px;
}
::v-deep .mytable-style .vxe-body--row.row-red {
  color: red;
}
</style>